import { Vector } from "./lib/math";
import { MassPoint } from "./lib/phy";
import { PhySystem } from "./system";

export interface MultMassPointVideo {
    pList: Vector[][];
    recordDt: number;
}
export const multMassPointVideo = (
    system: PhySystem<MassPoint[]>,
    recordDt: number,
    total_t: number,
): MultMassPointVideo => {
    const pointMap: Map<MassPoint, Vector[]> = new Map();

    system.state.forEach(point => {
        pointMap.set(point, [point.p]);
    });

    const update = (dt: number) => {
        system.update(dt);
        pointMap.forEach((vectors, point) =>
            vectors.push(point.p));
    }

    for (let t = 0; t < total_t; t += recordDt)
        update(recordDt);

    return {
        pList: Array.from(pointMap.values()),
        recordDt,
    };
}
